function Content(id, title, date, image, type, name, status, collect) {
	this.id = id;
	this.title = title;
	this.date = date;
	this.image = image;
	this.type = type;
	this.name = name;
	this.status = status;// status_yes --- not completed status_no --- completed
	this.collect = collect;
}

function getText(elem) {
	var text = "";
	if (elem) {
		if (elem.childNodes) {
			for (var i = 0; i < elem.childNodes.length; i++) {
				var child = elem.childNodes[i];
				if (child.nodeValue){
					text += child.nodeValue;
				}
				else {
					if (child.childNodes[0]){
						if (child.childNodes[0].nodeValue){
							text += child.childNodes[0].nodeValue;
						}
					}
				}
			}
		}
	}
	return text;
}

var ajaxReq = new AjaxRequest();
var content = new Array();

function loadContent(){
	document.getElementById("content").innerHTML = "<img src='wait.gif'  id='waitImage' alt='Loading...' />";
	//ajaxReq.send("GET", "zzz.xml", handleRequest);
	sendXMLPost("PersonContent","<username>"+getUserName()+"</username>", handleRequest);
}

function handleRequest(responseXML) {
	//if (ajaxReq.getReadyState() == 4 && ajaxReq.getStatus() == 200) {
		var xmlData = responseXML.getElementsByTagName("content")[0];
		
		var entries = xmlData.getElementsByTagName("entry");
		//alert("entries.length "+entries.length);
		for (var i = 0; i < entries.length; i++) {
			content.push(new Content(
					getText(entries[i].getElementsByTagName("id")[0]), 
					getText(entries[i].getElementsByTagName("title")[0]),
					getText(entries[i].getElementsByTagName("date")[0]),
					getText(entries[i].getElementsByTagName("image")[0]),
					getText(entries[i].getElementsByTagName("type")[0]),
					getText(entries[i].getElementsByTagName("author")[0]),
					getText(entries[i].getElementsByTagName("status")[0]),
					getText(entries[i].getElementsByTagName("collect")[0])));
			if(content[i].type == "myJoin"){
				allMyJoinContentCounts++;
			}else if(content[i].type == "myDifficulty"){
				allMyDifficultyContentCounts++;
			}else if(content[i].type == "myLove"){
				allMyLoveContentCounts++;
			}
			allContentCounts++;
		}
	//}
	
	if(allMyJoinContentCounts == 0){
		allMyJoinPageCounts = 0;
	}else{
		if(parseInt(allMyJoinContentCounts%4) == 0){
			allMyJoinPageCounts =  parseInt(allMyJoinContentCounts/4);
		}else{
			allMyJoinPageCounts =  parseInt(allMyJoinContentCounts/4) + 1;
		}
	}
	
	if(allMyDifficultyContentCounts == 0){
		allMyDifficultyPageCounts = 0;
	}else{
		if(parseInt(allMyDifficultyContentCounts%4) == 0){
			allMyDifficultyPageCounts =  parseInt(allMyDifficultyContentCounts/4);
		}else{
			allMyDifficultyPageCounts =  parseInt(allMyDifficultyContentCounts/4) + 1;
		}
	}
	
	if(allMyLoveContentCounts == 0){
		allMyLovePageCounts = 0;
	}else{
		if(parseInt(allMyLoveContentCounts%4) == 0){
			allMyLovePageCounts =  parseInt(allMyLoveContentCounts/4);
		}else{
			allMyLovePageCounts =  parseInt(allMyLoveContentCounts/4) + 1;
		}
	}
	
	if(allContentCounts == 0){
		allPageCounts = 0;
	}else{
		if(parseInt(allContentCounts%4) == 0){
			allPageCounts =  parseInt(allContentCounts/4);
		}else{
			allPageCounts =  parseInt(allContentCounts/4) + 1;
		}
	}
	isFirst = true;
	showContent("myDifficulty", 1);
	
	setUserName();
	var userNode = xmlData.getElementsByTagName("user")[0];
	document.getElementById("personPage_name").innerHTML = getText(userNode.getElementsByTagName("name")[0]);
	document.getElementById("personPage_description").innerHTML = getText(userNode.getElementsByTagName("description")[0]);
	document.getElementById("personPage_email").innerHTML = getText(userNode.getElementsByTagName("email")[0]);
	document.getElementById("personPage_gender").innerHTML = getText(userNode.getElementsByTagName("gender")[0]);
	document.getElementById("personPage_phone").innerHTML = getText(userNode.getElementsByTagName("phone")[0]);
	document.getElementById("personPage_image").innerHTML = "<img src='"+getText(userNode.getElementsByTagName("image")[0])+"'/>";
}

function setUserName() {
	document.getElementById("welcomeText").innerHTML = "欢迎回来，" + getUserName();
}

var isFirst = true;

var allMyJoinContentCounts = 0;
var allMyDifficultyContentCounts = 0;
var allMyLoveContentCounts = 0;
var allContentCounts = 0;
var allMyJoinPageCounts = 0;
var allMyDifficultyPageCounts = 0;
var allMyLovePageCounts = 0;
var allPageCounts = 0;

var displayContent = new Array();
var currentPage = 1;



function showContent(type, pageNumber){
	displayContent.length = 0;
	currentPage = pageNumber;
	
	var node = document.getElementById("content");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	
	//alert(currentPage);
	if(type == "myDifficulty"){
		var i = 0;
		while (i < content.length) {
			if(content[i].type == "myDifficulty"){
				displayContent.push(content[i]);
			}		
			i++;
		}
		var k = 0, contentListHTML = "";
		while(k < displayContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += displayContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allMyDifficultyPageCounts;
	}else if(type == "myJoin"){
		var i = 0;
		while (i < content.length) {
			if(content[i].type == "myJoin"){
				displayContent.push(content[i]);
			}		
			i++;
		}
		var k = 0, contentListHTML = "";
		while(k < displayContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += displayContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allMyJoinPageCounts;
	}else if(type == "myLove"){
		var i = 0;
		while (i < content.length) {
			if(content[i].type == "myLove"){
				displayContent.push(content[i]);
			}		
			i++;
		}
		var k = 0, contentListHTML = "";
		while(k < displayContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += displayContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allMyLovePageCounts;
	}
	if(isFirst){		
		addPages(displayContent.length, lengthToPage(displayContent.length));
		//var number =  parseInt(pageNumber%6);
		setPage(pageNumber);
	}	
		
	document.getElementById("content").innerHTML = decodeURIComponent(contentListHTML);
}

Content.prototype.toHTML = function() {
	var contentHTML = "";

	if (this.image) {
		contentHTML += "<div class='textTag' id='"
				+ this.id
				+ "'>"
				+ "<div class='personPhoto'><img src='"
				+ this.image
				+ "'/></div>"
				+ "<div class='personNameLabel'><span id='personNameLabel'>姓名：</span></div>"
				+ "<div class='personName'><span id='personName'>"
				+ this.name
				+ "</span></div>"
				+ "<div class='titleLabel'><span id='titleLabel'>标题：</span></div>"
				+ "<div class='title'><span id='title'>"
				+ this.title
				+ "</span></div>"
				+ "<div class='timeLabel'><span id='timeLabel'>时间：</span></div>"
				+ "<div class='time'><span id='time'>"
				+ this.date
				+ "</span></div>"
				+ "<div class='"
				+ this.status
				+ "'><span id='status'></span></div>"
				+ "<div><span id='collectButton' class='"
				+ this.collect
				+ "' onclick='collectButtonClicked();'></span></div>"
				+ "<div class='mainReply'><span id='mainReply' onclick='openContentPage(event);'></span></div>"
				+ "</div>";
	} else {
		contentHTML += "<div class='textTag' id='"
				+ this.id
				+ "'>"
				+ "<div class='personPhoto'><img src='#'/></div>"
				+ "<div class='personNameLabel'><span id='personNameLabel'>姓名：</span></div>"
				+ "<div class='personName'><span id='personName'>"
				+ this.name
				+ "</span></div>"
				+ "<div class='titleLabel'><span id='titleLabel'>标题：</span></div>"
				+ "<div class='title'><span id='title'>"
				+ this.title
				+ "</span></div>"
				+ "<div class='timeLabel'><span id='timeLabel'>时间：</span></div>"
				+ "<div class='time'><span id='time'>"
				+ this.date
				+ "</span></div>"
				+ "<div class='"
				+ this.status
				+ "'><span id='status'></span></div>"
				+ "<div><span id='collectButton' class='"
				+ this.collect
				+ "' onclick='collectButtonClicked();'></span></div>"
				+ "<div class='mainReply'><span id='mainReply' onclick='openContentPage(event);'></span></div>"
				+ "</div>";
	}
	return contentHTML;
};

function askTagClicked(){
	isFirst = true;
	showContent("myDifficulty", 1);
	focusTag("myDifficulty");
	typeFlag = "myDifficulty";
	showSubmit();
}

function helpTagClicked(){
	isFirst = true;
	showContent("myJoin", 1);
	focusTag("myJoin");
	typeFlag = "myJoin";
	submitHide();
}

function loveTagClicked(){
	isFirst = true;
	showContent("myLove", 1);
	focusTag("myLove");
	typeFlag = "myLove";
	submitHide();
}

function focusTag(type){
	if(type == "myDifficulty"){
		document.getElementById("askTag").className = "askTagChecked";
		document.getElementById("helpTag").className = "helpTagNormal";
		document.getElementById("loveTag").className = "loveTagNormal";
	}else if(type == "myJoin"){
		document.getElementById("askTag").className = "askTagNormal";
		document.getElementById("helpTag").className = "helpTagChecked";
		document.getElementById("loveTag").className = "loveTagNormal";
	}else if(type == "myLove"){
		document.getElementById("askTag").className = "askTagNormal";
		document.getElementById("helpTag").className = "helpTagNormal";
		document.getElementById("loveTag").className = "loveTagChecked";
	}
}

var typeFlag = "myDifficulty";

function changePage(flag){
	var pageID = setPage(flag);
	var pageNumber = parseInt(document.getElementById(pageID).firstChild.nodeValue);
	currentPage = pageNumber;
	isFirst = false;
	showContent(typeFlag, pageNumber);
}

function setPage(flag){
	var pageID;
	if(flag == 1 || flag == "1"){
		pageID = "pageNumber1";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_checked";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 2 || flag == "2"){
		pageID = "pageNumber2";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_checked";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 3 || flag == "3"){
		pageID = "pageNumber3";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_checked";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 4 || flag == "4"){
		pageID = "pageNumber4";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_checked";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 5 || flag == "5"){
		pageID = "pageNumber5";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_checked";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 6 || flag == "6"){
		pageID = "pageNumber6";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_checked";
		}
	}else if(flag == 7 || flag == "7"){
		changePage(5);
		nextPage();
	}else if(flag == 0 || flag == "0"){
		if(document.getElementById("page2")){
			changePage(2);
		}else{
			return;
		}
		frontPage();
	}else{
		return;
	}
	return pageID;
	
}

function addPages(contentCounts, pageCounts){
	var node = document.getElementById("Pages");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	
	var num;
	var pageCountArray = new Array();
	
	for( num = 1; num <= contentCounts; num++ ){
		pageCountArray.push(num);	
	}	
	if(pageCounts>=6){
		node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>" + 6 + "</font></span>";
		node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + 5 + "</font></span>";	
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + 4 + "</font></span>";	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";		
	}else if(pageCounts==5){
		node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + 5 + "</font></span>";	
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + 4 + "</font></span>";	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";	
	}else if(pageCounts==4){
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + 4 + "</font></span>";	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else if(pageCounts==3){	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else if(pageCounts==2){
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else if(pageCounts==1){
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else{
	 //alert("empty");
	}
}

function frontPage(){
	var i = 0;
	if(displayContent.length == 0){
		return;
	}
	if(parseInt(document.getElementById("pageNumber1").firstChild.nodeValue) == currentPage){
		if(currentPage == 1){
			return;
		}else{
			alert("!");
		}
	}else if(parseInt(document.getElementById("pageNumber2").firstChild.nodeValue) == currentPage){
		changePage(1);
		if(currentPage == 1){
			return;
		
		}else{
			moveRightPageNumber();
		}
	}else if(parseInt(document.getElementById("pageNumber3").firstChild.nodeValue) == currentPage){
		changePage(2);
	}else if(parseInt(document.getElementById("pageNumber4").firstChild.nodeValue) == currentPage){
		changePage(3);
	}else if(parseInt(document.getElementById("pageNumber5").firstChild.nodeValue) == currentPage){
		changePage(4);
	}else if(parseInt(document.getElementById("pageNumber6").firstChild.nodeValue) == currentPage){
		changePage(5);
	}
}


function nextPage(){
	var lastPage;
	lastPage = lengthToPage(displayContent.length);
	
	if(document.getElementById("pageNumber6") && parseInt(document.getElementById("pageNumber6").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){			
			return;
		}else{
			alert("!");
		}
	}else if(document.getElementById("pageNumber5") && parseInt(document.getElementById("pageNumber5").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(6);
		if(currentPage == lastPage){
			return;	
		}else{
			moveLeftPageNumber();
		}
	}else if(document.getElementById("pageNumber4") && parseInt(document.getElementById("pageNumber4").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(5);
	}else if(document.getElementById("pageNumber3") && parseInt(document.getElementById("pageNumber3").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(4);
	}else if(document.getElementById("pageNumber2") && parseInt(document.getElementById("pageNumber2").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(3);
	}else if(document.getElementById("pageNumber1") && parseInt(document.getElementById("pageNumber1").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(2);
	}
}

function moveLeftPageNumber(){
	
	var node = document.getElementById("Pages");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	var num6 = currentPage+1;
	var num5 = currentPage;
	var num4 = currentPage-1;
	var num3 = currentPage-2;
	var num2 = currentPage-3;
	var num1 = currentPage-4;
	node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>" + num6 + "</font></span>";
	node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + num5 + "</font></span>";	
	node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + num4 + "</font></span>";	
	node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + num3 + "</font></span>";	
	node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + num2 + "</font></span>";	
	node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + num1 + "</font></span>";		
		//alert("currenPage "+ currentPage);
	changePage(5);
}

function moveRightPageNumber(){
	var node = document.getElementById("Pages");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	
	var num6 = currentPage+4;
	var num5 = currentPage+3;
	var num4 = currentPage+2;
	var num3 = currentPage+1;
	var num2 = currentPage;
	var num1 = currentPage-1;
	
	node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>" + num6 + "</font></span>";
	node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + num5 + "</font></span>";	
	node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + num4 + "</font></span>";	
	node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + num3 + "</font></span>";	
	node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + num2 + "</font></span>";	
	node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + num1 + "</font></span>";	
	changePage(2);
}


function lengthToPage(length){
	var page;
	if(length == 0){
		page = 0;
	}else{
		if(parseInt(length%4) == 0){
			page = parseInt(length/4);
		}else{
			page = parseInt(length/4) + 1;
		}
	}
	return page;
}

function lastPage(){
	var lastPage;
	lastPage = lengthToPage(displayContent.length);
	var i = 0;
	for(i = 0; i < lastPage; i++){
		nextPage();
	}
	
}

function firstPage(){
	var lastPage;
	lastPage = lengthToPage(displayContent.length);
	for(i = 0; i < lastPage; i++){
		frontPage();
	}
}

function goButtonClicked(){
	if(!document.getElementById("pageSelect").value || document.getElementById("pageSelect").value == 0){
		alert("请输入正确的页数");
	}else{
		var i;
		var gap = parseInt(document.getElementById("pageSelect").value)-currentPage;
		if(parseInt(document.getElementById("pageSelect").value) > currentPage){
			for(i = 0; i < gap; i++){
				nextPage();
			}
		}else{
			for(i = 0; i < -gap; i++){
				frontPage();
			}
		}
	}
}

function collectButtonClicked() {
	var arguments = "<collect>";
	arguments = addTag(arguments, "username", getUserName());
	arguments = addTag(arguments, "id",
			event.srcElement.parentElement.parentElement.id);

	if (window.event.srcElement.className == "collectButton_no") {
		window.event.srcElement.className = "collectButton_yes";

		arguments = addTag(arguments, "isCollected", "yes");

	} else {
		window.event.srcElement.className = "collectButton_no";
		// arguments = addTag(arguments, "id",
		// event.srcElement.parentElement.parentElement.id);
		arguments = addTag(arguments, "isCollected", "no");
	}
	arguments += "</collect>";
	sendXMLPost("SetCollect", arguments, null);

}

function submitButton_down_Clicked(){
	var arguments = "<content>";
	arguments = addTag(arguments, "username", getUserName());
	arguments = addTag(arguments, "title", document.getElementById("title_down_text").value);
	arguments = addTag(arguments, "body", document.getElementById("detail_down_text").value);
	var category_name = document.getElementById("type_down_text").value;
	if (category_name == "课程") {
		arguments = addTag(arguments, "category", "course");
	} else if(category_name == "生活") {
		arguments = addTag(arguments, "category", "life");
	} else if(category_name == "活动") {
		arguments = addTag(arguments, "category", "activity");
	} else if(category_name == "找对象") {
		arguments = addTag(arguments, "category", "find");
	} else if(category_name == "其他") {
		arguments = addTag(arguments, "category", "another");
	} 
	arguments = addTag(arguments, "date", document.getElementById("datepicker-example1").value);
	arguments = addTag(arguments, "reward", document.getElementById("forward_down_text").value);
	arguments += "</content>";
	var url = "CreatePost";
	sendXMLPost(url, arguments, handler);
	//var title = document.getElementById("title_down_text").valueOf();
}
function handler() {window.location.reload();}

function showSubmit(){
	if(document.getElementById("submitContent").className == "submitContent_Hide"){
		document.getElementById("submitContent").className = "submitContent_Show";
	}
	if(document.getElementById("submitContent").className == "submitContent_Show"){
		
		document.getElementById("submitContent").innerHTML = "<div class='title_down'><span id='title_down_Label'>标题：</span><input id='title_down_text' /></div><div class='detail_down'><span id='detail_down_Label'>内容：</span><textarea name='detail_down_text' cols='60' rows='7' id='detail_down_text'></textarea></div><div class='deadline_down'><span id='deadline_down_Label'>截止时间：</span><input id='datepicker-example1' type='text' size='12'/><span id='deadline_down_Help'></span></div><div class='forward_down'><span id='forward_down_Label'>给予报酬：</span><input id='forward_down_text' size='70'/></div><div class='type_down'><span id='type_down_Label'>任务类型：</span><select name='type_down_text' id='type_down_text'><option> 课程 </option><option> 生活 </option><option> 活动 </option><option> 找对象 </option><option> 其他 </option></select></div><div class='submitButton_down' onclick='submitButton_down_Clicked();'><span id='submitButton_down_Button' class='submitButton_down_Button'></span></div>";
		window.location.reload();

	}
}

function submitHide(){
	if(document.getElementById("submitContent").className == "submitContent_Show"){
		document.getElementById("submitContent").className = "submitContent_Hide";
	}
	if(document.getElementById("submitContent").className == "submitContent_Hide"){
		var node = document.getElementById("submitContent");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
	}
}

function openPersonPage(){
	window.open("personPage.html","_blank");
}

function openContentPage(){
	document.cookie = "taskId = " + event.srcElement.parentElement.parentElement.id;
	window.open("contentPage.html","_blank");
}


function logOut() {
	window.location.href = "index.html";
}

function changeKey(){
	window.location.href = "changeKey.html";
}